<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="d" uri="/doone-comm-ui-tags"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>"></base>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></title>
		<!-- Libraries -->
		<link type="text/css" href="<%=path%>/manage/css/layout.css"
			rel="stylesheet" />
		<link type="text/css" href="<%=path%>/manage/css/new_style.css"
			rel="stylesheet" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/manage/css/Tooltip.css" />
		<link type="text/css"
			href="<%=path%>/manage/page/user/css/users_style.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery_form.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/easyTooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/hoverIntent.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/Tooltip.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/errorTip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.methods.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.defaults.js"></script>
		<script language="javascript" type="text/javascript">
	$(function() {
		var dialogOpts = {
			autoOpen : false,
			width : 550,
			height : 200,
			modal : true,
			title : '选择图片',
			buttons : {
				"保存" : function() {
					var edit = $("#editFlag").val();
					if (edit == "edit") {
						$("#addLevel").attr("action",
								root + "/clientuser/updateUserLevel.action");
						$("#addLevel").submit();
					} else {
						$("#addLevel").submit();
					}
				}
			},
			close : function() {
				//清除file输入框里的值
				//$("#addLevelDialog").dialog("close");
			}
		}
		$("#addLevelDialog").dialog(dialogOpts);
		//y验证
		$("#addLevel").validate({
			rules : {
				"userPointRanks.rankName" : {
					required : true
				},
				"userPointRanks.minPoints" : {
					required : true,
					number : true
				},
				"userPointRanks.maxPoints" : {
					required : true,
					number : true
				}
			},
			messages : {
				"userPointRanks.rankName" : {
					required : "等级名称必填"

				},
				"userPointRanks.minPoints" : {
					required : "最小积分必填",
					number : "必需是数字"
				},
				"userPointRanks.maxPoints" : {
					required : "最大积分必填",
					number : "必需是数字"
				}
			}
		});
	});
	function openAddLevel() {
		$("#addLevelDialog").dialog("open");
	}
	function getUserlevel(levelId) {
		$.ajax({
			url : root + '/clientuser/getUserlevelById.action?levelId='
					+ levelId,
			method : 'post',
			dataType : 'json',
			success : function(data) {
				var userRanks = data.userPointRanks;
				$("#rankName").val(userRanks.rankName);
				$("#minPoints").val(userRanks.minPoints);
				$("#maxPoints").val(userRanks.maxPoints);
				$("#levelId").val(userRanks.id);
				$("#editFlag").val("edit");
				$("#addLevelDialog").dialog("open");
			},
			error : function(err) {
				if (err.responseText != '')
					alert(err.responseText);
				else
					alert("请求失败！");
			}
		});
	}
	function deleteUserlevel(levelId) {
		if (confirm("确定要删除该条记录")) {
			$.ajax({
				url : root + '/clientuser/deleteUserLevel.action?levelId='
						+ levelId,
				method : 'post',
				dataType : 'json',
				success : function(data) {
					window.location.href = root
							+ "/clientuser/getUserLevelInit.action";
				},
				error : function(err) {
					if (err.responseText != '')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
	}
</script>
	</head>
	<body>
		<div>
			<p class="sitemap">
				当前位置：用户信息管理 > 用户配置管理
			</p>
			<h1>
				用户配置管理
			</h1>
			<div>

				<!-- Tabs -->
				<div id="tabs">
					<ul>
						<li>
							<a href="#tabs-1">用户等级</a>
						</li>
					</ul>
					<div class="bottom_line">
						<a href="javascript:openAddLevel();" class="btn_addnew">新增等级</a>
					</div>
					<s:hidden name="editFlag" id="editFlag"></s:hidden>
					<table class="fullwidth" cellpadding="0" cellspacing="0"
						id="enterInfoTab">
						<thead>
							<tr>
								<td>
									等级称号
								</td>
								<td>
									积分大于
								</td>
								<td>
									等级图标
								</td>
								<td>
									操作
								</td>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="userPointList">
								<tr class="odd">
									<td>
										<s:property value="rankName" />
									</td>
									<td>
										<s:property value="maxPoints" />
									</td>
									<td>
										<img src="<%=serverUrl%><s:property value="rankImg" />"
											width="100px" height="100px">
									</td>
									<td>
										<a class="icon icon_edit" title="编辑"
											href="javascript:getUserlevel(<s:property value="id" />)"></a>
										<a class="icon icon_delete" title="删除"
											href="javascript:deleteUserlevel(<s:property value="id" />)"></a>
									</td>
								</tr>
							</s:iterator>
						</tbody>
					</table>
					<!-- 分页标签开始 -->
					<div align="right" style="float: right;">
						<d:page id="pageLevel" template="details" skin="gray">
						</d:page>
					</div>
					<!-- 分页标签结束 -->

				</div>
			</div>
		</div>



		<!-- 新增等级dialog -->
		<div id="addLevelDialog" style="display: none;">
			<form id="addLevel" method="post" enctype="multipart/form-data"
				action="<%=path%>/clientuser/addUserLevel.action">
				<s:hidden name="userPointRanks.id" id="levelId"></s:hidden>
				<table border="0" cellspacing="1" cellpadding="0">
					<tr>
						<td>
							等级图片：
						</td>
						<td>
							<span id="updImgArea"><input id="fileupload"
									name="fileMaterial" type="file" /> </span>
							<div id="message" style="font-size: 14px"></div>
						</td>
					</tr>
					<tr>
						<td>
							等级称号：
						</td>
						<td>
							<input type="text" name="userPointRanks.rankName" id="rankName">
						</td>
					</tr>
					<tr>
						<td>
							积分大于
						</td>
						<td>
							<input type="text" name="userPointRanks.maxPoints" id="maxPoints">
						</td>
					</tr>

				</table>
			</form>
		</div>

	</body>
</html>
